package levels
{
	import org.flixel.*;
	import org.flixel.plugin.photonstorm.*;
	
	import enemies.*;
	import interactions.*;
	import items.*;
	import treasures.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class Tutorial_2 extends Level
	{
		private static const STARTED:uint = 0;
		private static const SPAWNED:uint = 1;
		
		private var _state:uint;
		private var _timer:FlxDelay;
		private var _asd:FlxSprite;
		private var _pressA:FlxText;
		private var _sb:SpeedBooster;
		
		override public function create():void
		{
			super.create();
			
			_checkGameOver = false;
			
			_asd = new FlxSprite();
			_asd.loadGraphic(Assets.ImgASD, true, false, 430, 144);
			_asd.x = FlxG.width / 2 - _asd.width / 2;
			_asd.y = 100;
			_asd.addAnimation("default", [0], 6, false);
			_asd.addAnimation("blink", [0, 1], 6, true);
			_asd.play("default");
			_animations.add(_asd);
			
			_state = STARTED;
			
			_maze.load(MazeData.tutorial_2);
			Player.spawnAt(7, 11);
			
			Tracker.minScore = 1;
			Tracker.mapScore = 1000;
			Tracker.lives = 0;
			
			addEntity(new LootBag(3, 17));
			
			_sb = addEntity(new SpeedBooster(13, 11)) as SpeedBooster;
			_sb.addText("info", "Speed Boost", 70, 2);
			
			_pressA = new FlxText(0, 0, FlxG.width);
			_pressA.text = "Press A, S, or D to use item";
			_pressA.font = "cooper_black";
			_pressA.alignment = "center";
			_pressA.size = 23;
			_pressA.y = 300;
			_pressA.x = FlxG.width / 2 - _pressA.width / 2;
			_pressA.exists = false;
			add(_pressA);
			
			var keyLights:Light = new Light(10, 6);
			keyLights.scale.make(10, 10);
			
			var keyLights2:Light = new Light(20, 6);
			keyLights2.scale.make(10, 10);
			
			gameStart();
		}
		
		override public function update():void
		{
			super.update();
			
			if (_state == STARTED)
			{
				if (!_player.notMoving)
				{
					_state = SPAWNED;
					Animation.intruderWarning();
					//Animation.finger(Maze.getTileCenterByIndex(13, 11));
					var r:Robber = addEntity(new Robber(28, 17)) as Robber;
					r.randomizeSpeed = false;
					r.setBaseSpeed(108);
				}
				else
				{
					_sb.say("info");
				}
			}
			if (_state == SPAWNED)
			{
				if (!StatusEffect.speedBoosted && _ui._itemOne != null)
				{
					_asd.play("blink");
					_pressA.exists = true;
					
				}
				else
				{
					_pressA.exists = false;
					_asd.play("default");
				}
				
				if (_treasures.length <= 0 && _enemies.length <= 0)
				{
					logGameEnd();
					FlxG.resetState();
				}
				
				if (_enemies.countLiving() <= 0)
				{
					_checkGameOver = true;
				}
			}
		}
	}
}